﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lianxi2
{
    public partial class index : System.Web.UI.Page
    {
        public static List<gongshang> gs = new List<gongshang>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                gs.Clear();
                gongshang g1 = new gongshang() { Id = 1, Leibie = "夹具", Name = "钢架玩栓球承载力实验夹", Salary = "¥12550.00", Tigong = "启程实业",Riqi="2019年12月1日", Zhuangtai = "报废" };
                gongshang g2 = new gongshang() { Id = 2, Leibie = "检具", Name = "尼龙管工装检具", Salary = "¥550.00", Tigong = "德祐科技", Riqi = "2019年12月1日", Zhuangtai = "报废" };
                gongshang g3 = new gongshang() { Id = 3, Leibie = "检具", Name = "钢管", Salary = "¥2550.00", Tigong = "华建实业", Riqi = "2019年12月1日", Zhuangtai = "报废" };
                gongshang g4 = new gongshang() { Id = 4, Leibie = "检具", Name = "钢架玩栓球承载力实验夹", Salary = "¥12550.00", Tigong = "启程实业", Riqi = "2019年12月1日", Zhuangtai = "报废" };
                gongshang g5 = new gongshang() { Id = 5, Leibie = "夹具", Name = "钢架玩栓球承载力实验夹", Salary = "¥12550.00", Tigong = "启程实业", Riqi = "2019年12月1日", Zhuangtai = "报废" };
                gongshang g6 = new gongshang() { Id = 6, Leibie = "夹具", Name = "钢架玩栓球承载力实验夹", Salary = "¥12550.00", Tigong = "启程实业", Riqi = "2019年12月1日", Zhuangtai = "报废" };
                gongshang g7 = new gongshang() { Id = 7, Leibie = "夹具", Name = "钢架玩栓球承载力实验夹", Salary = "¥12550.00", Tigong = "启程实业", Riqi = "2019年12月1日", Zhuangtai = "报废" };
                gongshang g8 = new gongshang() { Id = 8, Leibie = "检具", Name = "尼龙管工装检具", Salary = "¥550.00", Tigong = "德祐科技", Riqi = "2019年12月1日", Zhuangtai = "报废" };
                gongshang g9 = new gongshang() { Id = 9, Leibie = "检具", Name = "钢管", Salary = "¥2550.00", Tigong = "华建实业", Riqi = "2019年12月1日", Zhuangtai = "报废" };
                gongshang g10 = new gongshang() { Id = 10, Leibie = "检具", Name = "钢架玩栓球承载力实验夹", Salary = "¥12550.00", Tigong = "启程实业", Riqi = "2019年12月1日", Zhuangtai = "报废" };
                gongshang g11 = new gongshang() { Id = 11, Leibie = "夹具", Name = "钢架玩栓球承载力实验夹", Salary = "¥12550.00", Tigong = "启程实业", Riqi = "2019年12月1日", Zhuangtai = "报废" };
                gongshang g12 = new gongshang() { Id = 12, Leibie = "夹具", Name = "钢架玩栓球承载力实验夹", Salary = "¥12550.00", Tigong = "启程实业", Riqi = "2019年12月1日", Zhuangtai = "报废" };
                
                gs.Add(g1);
                gs.Add(g2);
                gs.Add(g3);
                gs.Add(g4);
                gs.Add(g5);
                gs.Add(g6);
                gs.Add(g7);
                gs.Add(g8);
                gs.Add(g9);
                gs.Add(g10);
                gs.Add(g11);
                gs.Add(g12);
                this.GridView1.DataSource = gs;
                this.GridView1.DataBind();

            }
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int id = Convert.ToInt32(this.GridView1.Rows[e.RowIndex].Cells[0].Text.ToString());
            gongshang shanchu = new gongshang();
            foreach (var item in gs)
            {
                if (id == item.Id)
                {
                    shanchu = item;

                }

            }
            gs.Remove(shanchu);
            this.GridView1.DataSource = gs;
            this.GridView1.DataBind();
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            this.GridView1.EditIndex = e.NewEditIndex;
            this.GridView1.DataSource = gs;
            this.GridView1.DataBind();
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int id = Convert.ToInt32(((TextBox)this.GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text);
            foreach (var item in gs)
            {
                if (id == item.Id)
                {
                    item.Leibie = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
                    item.Name = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
                    item.Salary = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
                    item.Tigong = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
                    item.Riqi = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
                    item.Zhuangtai = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text;
                }
            }
            this.GridView1.EditIndex = -1;
            this.GridView1.DataSource = gs;
            this.GridView1.DataBind();
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            this.GridView1.EditIndex = -1;
            this.GridView1.DataSource = gs;
            this.GridView1.DataBind();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            this.GridView1.DataSource = gs;
            this.GridView1.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            List<gongshang> lists = new List<gongshang>();
            int id = int.Parse(this.TextBox1.Text);
            for (int i = 0; i < gs.Count; i++)
            {
                if (gs[i].Id==id)
                {
                    lists.Add(gs[i]);
                }
            }
           
            this.GridView1.DataSource = lists;
            this.GridView1.DataBind();
        }
    }
}